﻿//JumbotCms_4.1 Final
using System;
using System.Data;
using System.IO;
using System.Web;
using System.Web.UI.WebControls;
using JumbotCms.Common;
namespace JumbotCms.WebFile.Admin
{
    public partial class _javascriptedit : JumbotCms.API.AdminCenter
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Admin_Load("0000", "html");
            id = Str2Str(q("id"));
            if (!Page.IsPostBack)
            {
                doh.Reset();
                doh.SqlCmd = "SELECT [code],[Title] FROM [jcms_normal_templatecontentli] ORDER BY Id asc";
                DataTable dtJumbotLi = doh.GetDataTable();
                this.ddlJumbotLiCode.DataSource = dtJumbotLi;
                this.ddlJumbotLiCode.DataTextField = "Title";
                this.ddlJumbotLiCode.DataValueField = "Code";
                this.ddlJumbotLiCode.DataBind();
                dtJumbotLi.Clear();
                dtJumbotLi.Dispose();
            }
            Jumbot.DataOper.WebFormHandler wh = new Jumbot.DataOper.WebFormHandler(doh, "jcms_normal_javascript", btnSave);
            wh.AddBind(txtTitle, "Title", true);
            wh.AddBind(txtCode, "Code", true);
            wh.AddBind(txtTitleLen, "TitleLen", false);
            wh.AddBind(txtChannelId, "ChannelId", false);
            wh.AddBind(txtClassId, "ClassId", false);
            wh.AddBind(txtSelectNumber, "SelectNumber", false);
            wh.AddBind(ddlJumbotLiCode, "JumbotLiCode", false);
            if (id == "0")
            {
                this.txtCode.Text = GetRandomNumberString(64, false);
                wh.Mode = Jumbot.DataOper.OperationType.Add;
            }
            else
            {
                this.txtCode.Enabled = false;
                wh.ConditionExpress = "id=" + id;
                wh.Mode = Jumbot.DataOper.OperationType.Modify;
            }
            wh.validator = chkForm;
            wh.AddOk += new EventHandler(save_ok);
            wh.ModifyOk += new EventHandler(save_ok);
        }
        protected void bind_ok(object sender, EventArgs e)
        {
        }
        protected bool chkForm()
        {
            if (!CheckFormUrl())
                return false;
            if (!Page.IsValid)
                return false;
            doh.Reset();
            doh.ConditionExpress = "Code=@code and id<>" + id;
            doh.AddConditionParameter("@code", txtCode.Text);
            if (doh.Exist("jcms_normal_javascript"))
            {
                FinalMessage("代码重复!", "", 1);
                return false;
            }
            return true;
        }
        protected void save_ok(object sender, EventArgs e)
        {
            FinalMessage("成功保存", site.Dir + "admin/close.htm", 0);
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
        }
    }
}
